var loginStatus=false;
$(document).ready(function () {
    $("html").niceScroll();
    checkLogin()
})
function checkLogin(){
    loginStatus=false;
    var user = localStorage.getItem("user");
    if (user) {
        try{
            var userObj = JSON.parse(user);
            $("#login").text(userObj.username)
            loginStatus=true;
        }catch (e) {

        }
    }else {
        $("#login").text("点击登录")
    }
}
function loginClick(){
    if (loginStatus) {
        localStorage.removeItem("user");
        layer.msg("退出登录成功")
    }else {
        $('#loginModal').modal('show');
    }
    checkLogin()
}
function doLogin(){
   let username= $("#username").val()
   let password= $("#password").val()
    postAction("/auth.do",{username: username,password: password},(data)=>{
        if (data.code == 200) {
            layer.msg("登录成功")
        }
        localStorage.setItem("user", JSON.stringify(data.data));
        $('#loginModal').modal('hide');
         $("#username").val("");
         $("#password").val("")
        checkLogin()
    })
}
//菜单注册事件
// $(".nav li").on("click", function () {
//     $(".nav li").removeClass("active")
//     $(this).addClass("active")
// })
//右击菜单
document.oncontextmenu = function() {
    return false;
}
document.onmouseup=function(e){
    var menu= document.getElementById("right-menu")

    switch (menu.style.display){
        case "none":{
            if(e.button==2){
                console.log(e.clientX)
                console.log(e.clientY)
                menu.style.display="block"
                $("#right-menu").animate({
                    top:e.clientY-150+"px",
                    left:e.clientX-150+"px"

                },{
                    speed:"fast"
                })

                let positionX=e.clientX
                $(".menuItem").each(function(n,e){
                    if (positionX<(window.outerWidth/2)) {
                        switch(n){
                            case 0:{
                                $(e).animate({top:"0%"})
                                return;

                            }
                            case 1:{
                                $(e).animate({left:"85%",top:"15%"})
                                return;
                            }
                            case 2:{
                                $(e).animate({top:"85%",left:"85%"})
                                return;
                            }
                            case 3:{
                                $(e).animate({left:"85%"})
                                return;
                            }

                        }
                    }else {
                        switch(n){
                            case 0:{
                                $(e).animate({top:"0%",left:"50%"})
                                return;

                            }
                            case 1:{
                                $(e).animate({left:"50%",top:"30%"})
                                return;
                            }
                            case 2:{
                                $(e).animate({top:"85%",left:"15%"})
                                return;
                            }
                            case 3:{
                                $(e).animate({right:"85%"})
                                return;
                            }

                        }
                    }

                })
                /*  menu.style.top=e.clientY-150+"px"
                 menu.style.left=e.clientX-150+"px"  */

            }
            return
        }
        case "block":{
            menu.style.display="none"
            $(".menuItem").each(function(n,e){
                switch(n){
                    case 0:{
                        e.style.top="85%"
                        return;

                    }
                    case 1:{
                        e.style.left="85%"
                        return;
                    }
                    case 2:{
                        e.style.top="15%"
                        return;
                    }
                    case 3:{
                        e.style.left="15%"
                        return;
                    }

                }
            })
        }
    }

}

function music(){
    var audio=document.getElementById("audio")
    if(audio.paused){
        audio.play()
    }else{
        audio.pause()
    }
}




L2Dwidget.init({
    "pluginRootPath": "",
    "pluginJsPath": "",
    "pluginModelPath": "",
    "tagMode": false,
    "debug": false,
    "model": {
        "jsonPath": "resource/js/live2d/xuexiaoban/kesshouban.model.json"
    },
    "display": {
        "position": "right",
        "width": 325,
        "height": 300,
        "hOffset": -75,
        "vOffset": 0
    },
    "dialog": {
        "enable": true
    },
    "mobile": {
        "show": false
    },
    "react": {
        "opacity": 1
    },
    "log": false
});
